<template>
	<view v-if="privacyShow" class="privacy-popup">
		<u-modal :show="privacyShow" :showConfirmButton="false" :showCancelButton="false" confirmColor="#58be6b"
			cancelColor="#f2f2f2" :closeOnClickOverlay="true" width="550rpx" @confirm="confirm" @cancel="cancel"
			@close="cancel">
			<view class="slot-content">
				<view class="title">
					提示
				</view>
				<view class="text">
					在你使用{{wxAppName}}服务之前，请仔细阅读<text style="color: #666685;"
						@tap="go">《{{wxAppName}}小程序隐私保护指引》</text>如你同意该指引，请点击“同意”开始使用本小程序。
				</view>
				<view class="btn">
					<button class="cancel" @click="cancel">拒绝</button>
					<button class="confirm" id="confirm-btn" open-type="agreePrivacyAuthorization"
						@agreeprivacyauthorization="confirm">同意</button>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				privacyShow: false,
				wxAppName: "XXX",
			};
		},
		methods: {
			/**
			 * @description 打开、关闭隐私弹窗
			 */
			openPrivacyShow() {
				this.privacyShow = true;
			},
			closePrivacyShow() {
				this.privacyShow = false;
			},
			/**
			 * @description 同意
			 */
			confirm(e) {
				console.log("同意", e);
				// 告知平台用户已经同意，参数传同意按钮的id
				// this.resolvePrivacyAuthorization({
				// 	buttonId: "confirm-btn",
				// 	event: "agree"
				// });
				this.$emit("closePrivacyPopup", true);
			},
			/**
			 * @description 拒绝
			 */
			cancel(e) {
				console.log("拒绝", e);
				// 告知平台用户已经拒绝
				// this.resolvePrivacyAuthorization({
				// 	event: "disagree"
				// });
				this.$emit("closePrivacyPopup", false);
			},
			/**
			 * @description 跳转
			 */
			go() {
				uni.openPrivacyContract({
					success: (res) => {
						// 打开成功
						console.log("打开成功", res);
					},
					fail: (e) => {
						// 打开失败
						console.log("打开失败", e);
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
</style>